// Created by lifei on 2020/7/22--10:21.
<template>
  <div>
    <el-dialog :title="isEdit?'编辑':'新增'" :visible.sync="dialogVisible" width="1200px" :close-on-click-modal="false">
      <el-form ref="edit-form" :model="form" :rules="rules" class="form-wrap">
        <el-form-item label="物业名称" prop="name">
          <el-input v-halfCharCode v-model="form.name" placeholder="请输入物业名称" />
        </el-form-item>
        <el-form-item label="物业大类" prop="type">
          <el-select clearable v-model="form.type" placeholder="请选择物业大类">
            <el-option v-for="item in lists" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="项目小类" prop="type2">
          <el-select clearable v-model="form.type2" placeholder="请选择项目小类">
            <el-option v-for="item in lists" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="占地面积" prop="area">
          <el-input v-halfCharCode v-model="form.area" placeholder="请输入占地面积">
            <template slot="append">m²</template>
          </el-input>
        </el-form-item>
        <el-form-item label="建筑面积" prop="area2">
          <el-input v-halfCharCode v-model="form.area2" placeholder="请输入建筑面积">
            <template slot="append">m²</template>
          </el-input>
        </el-form-item>
        <el-form-item label="移交方式" prop="methods">
          <el-select clearable v-model="form.methods" placeholder="请选择移交方式">
            <el-option v-for="item in lists" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" class="full" prop="remark">
          <el-input v-halfCharCode v-model="form.remark" type="textarea" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="commit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "edit-match-info",
  data () {
    return {
      dialogVisible: false,
      form: {
        id: 0,
        name: '',
        type: '',
        type2: '',
        area: '',
        area2: '',
        methods: '',
        remark: '',
      },
      rules: {
        name: [
          { required: true, message: '请输入物业名称', trigger: 'blur' },
        ],
        type: [
          { required: true, message: '请选择物业大类', trigger: 'change' },
        ],
        type2: [
          { required: true, message: '请选择项目小类', trigger: 'change' },
        ],
        area: [
          { required: true, message: '请输入占地面积', trigger: 'blur' },
        ],
        area2: [
          { required: true, message: '请输入建筑面积', trigger: 'blur' },
        ],
        methods: [
          { required: true, message: '请选择移交方式', trigger: 'change' },
        ],

      },
      lists: [
        {
          value: '选项1',
          label: '黄金糕'
        }, {
          value: '选项2',
          label: '双皮奶'
        }, {
          value: '选项3',
          label: '蚵仔煎'
        }, {
          value: '选项4',
          label: '龙须面'
        }, {
          value: '选项5',
          label: '北京烤鸭'
        }
      ],
      isEdit: false
    }
  },
  mounted () {
  },
  methods: {
    show (data) {
      this.dialogVisible = true
      this.isEdit = false
      setTimeout(() => {
        this.$refs['edit-form'].resetFields()
        if (data) {
          console.log(JSON.stringify(data))
          this.isEdit = true
          let form = {}
          this.form = Object.keys(this.form).forEach(key => {
            form[key] = data[key]
          })
          this.form = form
        }
      }, 100)
    },
    commit () {
      this.$refs['edit-form'].validate(valid => {
        if (valid) {
          let params = Object.assign({}, this.form)
          if (this.isEdit) {
            this.$emit('updateData', params)
          } else {
            this.form.id = new Date().getTime()
            this.$emit('addData', params)
          }
          this.dialogVisible = false
        }
      })
    }
  }
}
</script>

<style scoped lang='scss'>
@include formWrap(3);
</style>

